package com.irdstudio.efp.cus.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.efp.cus.service.dao.CusIndivCashIncomeDao;
import com.irdstudio.efp.cus.service.domain.CusIndivCashIncome;
import com.irdstudio.efp.cus.service.facade.CusIndivCashIncomeService;
import com.irdstudio.efp.cus.service.vo.CusIndivCashIncomeVO;
import com.irdstudio.basic.framework.core.base.FrameworkService;
/**
 * <p>ServiceImpl: 客户(月均)现金流收入				<p>
 * @author chenqm1
 * @date 2018-05-08
 */
@Service("cusIndivCashIncomeService")
public class CusIndivCashIncomeServiceImpl implements CusIndivCashIncomeService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(CusIndivCashIncomeServiceImpl.class);

	@Autowired
	private CusIndivCashIncomeDao cusIndivCashIncomeDao;
	
	/**
	 * 新增操作
	 */
	public int insertCusIndivCashIncome(CusIndivCashIncomeVO inCusIndivCashIncomeVo) {
		logger.debug("当前新增数据为:"+ inCusIndivCashIncomeVo.toString());
		int num = 0;
		try {
			CusIndivCashIncome cusIndivCashIncome = new CusIndivCashIncome();
			beanCopy(inCusIndivCashIncomeVo, cusIndivCashIncome);
			String salary = inCusIndivCashIncomeVo.getSalary().toString();
			if(salary == null || salary == "")
				num = -2;
			else
				num = cusIndivCashIncomeDao.insertCusIndivCashIncome(cusIndivCashIncome);
			
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(CusIndivCashIncomeVO inCusIndivCashIncomeVo) {
		logger.debug("当前删除数据条件为:"+ inCusIndivCashIncomeVo);
		int num = 0;
		try {
			CusIndivCashIncome cusIndivCashIncome = new CusIndivCashIncome();
			beanCopy(inCusIndivCashIncomeVo, cusIndivCashIncome);
			num = cusIndivCashIncomeDao.deleteByPk(cusIndivCashIncome);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inCusIndivCashIncomeVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(CusIndivCashIncomeVO inCusIndivCashIncomeVo) {
		logger.debug("当前修改数据为:"+ inCusIndivCashIncomeVo.toString());
		int num = 0;
		try {
			CusIndivCashIncome cusIndivCashIncome = new CusIndivCashIncome();
			beanCopy(inCusIndivCashIncomeVo, cusIndivCashIncome);
			num = cusIndivCashIncomeDao.updateByPk(cusIndivCashIncome);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inCusIndivCashIncomeVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public CusIndivCashIncomeVO queryByPk(CusIndivCashIncomeVO inCusIndivCashIncomeVo) {
		
		logger.debug("当前查询参数信息为:"+ inCusIndivCashIncomeVo);
		try {
			CusIndivCashIncome queryCusIndivCashIncome = new CusIndivCashIncome();
			beanCopy(inCusIndivCashIncomeVo, queryCusIndivCashIncome);
			CusIndivCashIncome queryRslCusIndivCashIncome = cusIndivCashIncomeDao.queryByPk(queryCusIndivCashIncome);
			if (Objects.nonNull(queryRslCusIndivCashIncome)) {
				CusIndivCashIncomeVO outCusIndivCashIncomeVo = beanCopy(queryRslCusIndivCashIncome, new CusIndivCashIncomeVO());
				logger.debug("当前查询结果为:"+ outCusIndivCashIncomeVo.toString());
				return outCusIndivCashIncomeVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<CusIndivCashIncomeVO> queryAllOwner(CusIndivCashIncomeVO cusIndivCashIncomeVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<CusIndivCashIncomeVO> list = null;
		try {
			List<CusIndivCashIncome> cusIndivCashIncomes = cusIndivCashIncomeDao.queryAllOwnerByPage(cusIndivCashIncomeVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ cusIndivCashIncomes.size());
			pageSet(cusIndivCashIncomes, cusIndivCashIncomeVo);
			list = (List<CusIndivCashIncomeVO>) beansCopy(cusIndivCashIncomes, CusIndivCashIncomeVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<CusIndivCashIncomeVO> queryAllCurrOrg(CusIndivCashIncomeVO cusIndivCashIncomeVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<CusIndivCashIncome> cusIndivCashIncomes = cusIndivCashIncomeDao.queryAllCurrOrgByPage(cusIndivCashIncomeVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+cusIndivCashIncomes.size());
		List<CusIndivCashIncomeVO> list = null;
		try {
			pageSet(cusIndivCashIncomes, cusIndivCashIncomeVo);
			list = (List<CusIndivCashIncomeVO>) beansCopy(cusIndivCashIncomes, CusIndivCashIncomeVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<CusIndivCashIncomeVO> queryAllCurrDownOrg(CusIndivCashIncomeVO cusIndivCashIncomeVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<CusIndivCashIncome> cusIndivCashIncomes = cusIndivCashIncomeDao.queryAllCurrDownOrgByPage(cusIndivCashIncomeVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ cusIndivCashIncomes.size());
		List<CusIndivCashIncomeVO> list = null;
		try {
			pageSet(cusIndivCashIncomes, cusIndivCashIncomeVo);
			list = (List<CusIndivCashIncomeVO>) beansCopy(cusIndivCashIncomes, CusIndivCashIncomeVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}
}
